cl_inv = {}
cl_sweps = {}
cl_ships = {}
cl_foods = {}

local function cleaninv()
	table.Empty(cl_inv)
	table.Empty(cl_sweps)
	table.Empty(cl_ships)
	table.Empty(cl_foods)
end
usermessage.Hook("clearinv", cleaninv)

-- items --

local function recitem(um)
	local str = um:ReadString()
	local val = um:ReadShort()
	
	if val > 0 then
		cl_inv[str] = val
	else
		cl_inv[str] = nil
	end
end
usermessage.Hook("item", recitem)

-- sweps --

local function recswep(um)
	local key = um:ReadShort()
	local mdl = um:ReadString()
	local cls = um:ReadString()
	
	cl_sweps[key] = {model = mdl, class = cls}
end
usermessage.Hook("swep", recswep)

local function recsweprem(um)
	local key = um:ReadShort()
	
	cl_sweps[key] = nil
end
usermessage.Hook("swepgone", recsweprem)

-- foodies --

local function recfood(um)
	local key = um:ReadShort()
	local mdl = um:ReadString()
	local cls = um:ReadShort()
	
	cl_foods[key] = {model = mdl, amount = cls}
end
usermessage.Hook("food", recfood)

local function recfoodrem(um)
	local key = um:ReadShort()
	
	cl_foods[key] = nil
end
usermessage.Hook("foodgone", recfoodrem)

-- ships --

local function recship(um)
	local key = um:ReadShort()
	local mdl = um:ReadShort()
	local cls = um:ReadShort()
	
	cl_ships[key] = {cont = mdl, count = cls}
end
usermessage.Hook("ship", recship)

local function recshiprem(um)
	local key = um:ReadShort()
	
	cl_ships[key] = nil
end
usermessage.Hook("shipgone", recshiprem)

local function showmenu()

	-- Lua generated by DermaDesigner
	local DFrame1

	DFrame1 = vgui.Create('DFrame')
	DFrame1:SetSize(449, 326)
	DFrame1:Center()
	DFrame1:SetTitle('Inventory')
	DFrame1:SetSizable(false)
	DFrame1:MakePopup()
	
	-- End DD lua
	
	local sheet = vgui.Create("DPropertySheet")
	sheet:SetParent(DFrame1)
	sheet:SetPos(5,25)
	sheet:SetSize(439, 296)
	
	-- ITEMS --
	
	local list1 = vgui.Create("DPanelList")
	list1:SetSize(439, 296)
	list1:SetSpacing( 5 )
	list1:EnableHorizontal( false )
	list1:EnableVerticalScrollbar( true )
	
	for k,v in pairs(cl_inv) do
		local DPanel1 = vgui.Create('DPanel')
		DPanel1:SetSize(419, 74)
		
		local info = items[k] -- should be faster...
		
		local icon = vgui.Create("SpawnIcon", DPanel1)
		icon:SetModel(info.model)
		icon:SetPos(5,5)
		icon:SetMouseInputEnabled(false)
		
		local name = vgui.Create("DLabel", DPanel1)
		name:SetText(info.name)
		name:SizeToContents()
		name:SetPos(89, 5)
		
		local desc = vgui.Create("DLabel", DPanel1)
		desc:SetText(info.desc)
		desc:SizeToContents()
		desc:SetPos(89, 20)
		
		local amt = vgui.Create("DLabel", DPanel1)
		amt:SetText("Amount: " .. v)
		amt:SizeToContents()
		amt:SetPos(89, 54)
		
		local drop = vgui.Create("DButton", DPanel1)
		drop:SetSize(45, 15)
		drop:SetPos(310, 54)
		drop:SetText("Drop")
		drop.DoClick = function()
			RunConsoleCommand("drp_dropitem", k)
			DFrame1:Remove()
		end
		
		if info.useable then
			local use = vgui.Create("DButton", DPanel1)
			use:SetSize(45, 15)
			use:SetPos(360, 54)
			use:SetText("Use")
			use.DoClick = function()
				RunConsoleCommand("drp_useitem", k)
				DFrame1:Remove()
			end
		end
		
		list1:AddItem(DPanel1)
	end
	
	-- SWEPS --
	
	local list2 = vgui.Create("DPanelList")
	list2:SetSize(439, 296)
	list2:SetSpacing( 5 )
	list2:EnableHorizontal( false )
	list2:EnableVerticalScrollbar( true )
	
	for k,v in pairs(cl_sweps) do
		local DPanel1 = vgui.Create('DPanel')
		DPanel1:SetSize(419, 74)
		
		local info = weps[v.class] -- should be faster...
		
		local icon = vgui.Create("SpawnIcon", DPanel1)
		icon:SetModel(v.model)
		icon:SetPos(5,5)
		icon:SetMouseInputEnabled(false)
		
		local name = vgui.Create("DLabel", DPanel1)
		name:SetText(info.name)
		name:SizeToContents()
		name:SetPos(89, 5)
		
		local desc = vgui.Create("DLabel", DPanel1)
		desc:SetText(info.desc)
		desc:SizeToContents()
		desc:SetPos(89, 20)
		
		local drop = vgui.Create("DButton", DPanel1)
		drop:SetSize(45, 15)
		drop:SetPos(310, 54)
		drop:SetText("Drop")
		drop.DoClick = function()
			RunConsoleCommand("drp_dropswep", k)
			DFrame1:Remove()
		end
		
		local use = vgui.Create("DButton", DPanel1)
		use:SetSize(45, 15)
		use:SetPos(360, 54)
		use:SetText("Pickup")
		use.DoClick = function()
			RunConsoleCommand("drp_useswep", k)
			DFrame1:Remove()
		end
		
		list2:AddItem(DPanel1)
	end
	
	-- FOODS --
	
	local list3 = vgui.Create("DPanelList")
	list3:SetSize(439, 296)
	list3:SetSpacing( 5 )
	list3:EnableHorizontal( false )
	list3:EnableVerticalScrollbar( true )
	
	for k,v in pairs(cl_foods) do
		local DPanel1 = vgui.Create('DPanel')
		DPanel1:SetSize(419, 74)
		
		local info = foodies[v.model] -- should be faster...
		
		local icon = vgui.Create("SpawnIcon", DPanel1)
		icon:SetModel(v.model)
		icon:SetPos(5,5)
		icon:SetMouseInputEnabled(false)
		
		local name = vgui.Create("DLabel", DPanel1)
		name:SetText(info.name)
		name:SizeToContents()
		name:SetPos(89, 5)
		
		local desc = vgui.Create("DLabel", DPanel1)
		desc:SetText(info.desc)
		desc:SizeToContents()
		desc:SetPos(89, 20)
		
		local amt = vgui.Create("DLabel", DPanel1)
		amt:SetText("Fills " .. v.amount .. " hunger.")
		amt:SizeToContents()
		amt:SetPos(89, 35)
		
		local drop = vgui.Create("DButton", DPanel1)
		drop:SetSize(45, 15)
		drop:SetPos(310, 54)
		drop:SetText("Drop")
		drop.DoClick = function()
			RunConsoleCommand("drp_dropfood", k)
			DFrame1:Remove()
		end
		
		local use = vgui.Create("DButton", DPanel1)
		use:SetSize(45, 15)
		use:SetPos(360, 54)
		use:SetText("Eat")
		use.DoClick = function()
			RunConsoleCommand("drp_usefood", k)
			DFrame1:Remove()
		end
		
		list3:AddItem(DPanel1)
	end
	
	-- SHIPS --
	
	local list4 = vgui.Create("DPanelList")
	list4:SetSize(439, 296)
	list4:SetSpacing( 5 )
	list4:EnableHorizontal( false )
	list4:EnableVerticalScrollbar( true )
	
	for k,v in pairs(cl_ships) do
		local DPanel1 = vgui.Create('DPanel')
		DPanel1:SetSize(419, 74)
		
		local info = CustomShipments[v.cont]
		if not info then info = {name="N/A"} end
		
		local icon = vgui.Create("SpawnIcon", DPanel1)
		icon:SetModel("models/Items/item_item_crate.mdl")
		icon:SetPos(5,5)
		icon:SetMouseInputEnabled(false)
		
		local name = vgui.Create("DLabel", DPanel1)
		name:SetText(info.name)
		name:SizeToContents()
		name:SetPos(89, 5)
		
		local desc = vgui.Create("DLabel", DPanel1)
		desc:SetText("A shipment with " .. v.count .. " left.")
		desc:SizeToContents()
		desc:SetPos(89, 20)
		
		local drop = vgui.Create("DButton", DPanel1)
		drop:SetSize(45, 15)
		drop:SetPos(310, 54)
		drop:SetText("Drop")
		drop.DoClick = function()
			RunConsoleCommand("drp_dropship", k)
			DFrame1:Remove()
		end
		
		list4:AddItem(DPanel1)
	end
	
	sheet:AddSheet( "Items", list1, "gui/silkicons/plugin", false, false, "General Items" )
	sheet:AddSheet( "Weapons", list2, "gui/silkicons/bomb", false, false, "Things that go \"pew\"" )
	sheet:AddSheet( "Food", list3, "gui/silkicons/user", false, false, "Delicious Edibles" )
	sheet:AddSheet( "Shipments", list4, "gui/silkicons/box", false, false, "Various Packages" )
end
concommand.Add("drp_showinv", showmenu)